﻿using Azure;
using ERPEF.Model;
using ERPIService;
using Microsoft.EntityFrameworkCore;
using S4Project;
using System.Drawing;

namespace ERPService
{
    public class bs_WarehouseService : bs_WarehouseIService
    {
        private readonly MyDbContext MyDbContext;
        public bs_WarehouseService(MyDbContext myDb) 
        {
            this.MyDbContext = myDb;
        }
        //添加  
        public async Task<int> Add(bs_Warehouse bsWarehouse)
        {
            await MyDbContext.bs_Warehouse.AddAsync(bsWarehouse);
            return await MyDbContext.SaveChangesAsync();
        }
        //逻辑删除
        public async Task<int> Delete(int W_Id)
        {
            var del = MyDbContext.bs_Warehouse.Find(W_Id);
            if (del!=null)
            {
               del.IsDeleted = true;
                await MyDbContext.SaveChangesAsync();
                return 1;
            }
            return 0;
        }
        //查询
        public async Task<List<bs_Warehouse>> Query()
        {
            // return await MyDbContext.bs_Warehouse.ToListAsync();
            return await MyDbContext.bs_Warehouse
        .Where(w => w.IsDeleted == false) 
        .ToListAsync();
        }
        //修改
        public async Task<int> Update(bs_Warehouse bsWarehouse)
        {
                MyDbContext.bs_Warehouse.Update(bsWarehouse);
                return await MyDbContext.SaveChangesAsync();
        }
    }
}